package com.yan.furns.web.servlet;

import com.yan.furns.entity.Member;
import com.yan.furns.service.AdminService;
import com.yan.furns.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Yzb
 * @version 1.0
 */
public class AdminServlet extends BasicServlet {
	private AdminService adminService = new AdminServiceImpl();
	protected void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//		System.out.println("AdminServlet login");
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		if (adminService.query(username, password) != null) {
//			System.out.println("");
			req.getSession().setAttribute("member", new Member(-1, username, password, "admin@sohu.com"));
			req.getRequestDispatcher("/views/manage/manage_menu.jsp").forward(req, resp);
		} else {
			req.getRequestDispatcher("/views/manage/manage_login.jsp").forward(req, resp);
		}
	}
}
